//
//  KindsSlider.m
//  K8彩票
//
//  Created by zhoubo on 2017/6/7.
//  Copyright © 2017年 zhoubo. All rights reserved.
//

#import "KindsSlider.h"

#import "KindButton.h"
#import "HallLottery.h"

@interface KindsSlider ()

@property(nonatomic,strong)NSMutableArray* buttons;

@property(nonatomic,strong)NSArray* imgs;




@end

@implementation KindsSlider


-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = [UIColor purpleColor];
        
        self.buttons = [[NSMutableArray alloc]init];
        
        CGFloat width = [UIScreen mainScreen].bounds.size.width/3;
        
         self.imgs = @[NSLocalizedString(@"所有彩票", nil),NSLocalizedString(@"高频彩票", nil   ), NSLocalizedString(@"低频彩票", nil   )];
        
        for (int i = 0; i<3; i++) {
            KindButton* btn = [[KindButton alloc]initWithFrame:CGRectMake(width*i, 0, width, self.bounds.size.height)];
            
            

            
            [self.buttons addObject:btn];
            
            [btn setImgviewWithName:self.imgs[i]];
            
            
            

            
            
            [self addSubview:btn];
            
            [btn addTarget:self action:@selector(btnclick:) forControlEvents:UIControlEventTouchUpInside];
            
            btn.tag = i;
            
            if (i != 2) {
                UIView* view = [[UIView alloc]initWithFrame:CGRectMake(width*(i+1), self.bounds.size.height*0.1, 0.5, self.bounds.size.height*0.8)];
                [self addSubview:view];
                view.backgroundColor = [UIColor colorWithWhite:230/255.0 alpha:1];
            }
            
            
            UIView* view = [[UIView alloc]initWithFrame:CGRectMake(0, self.bounds.size.height, width*3, 1)];
            [self addSubview:view];
            view.backgroundColor = [UIColor colorWithWhite:210/255.0 alpha:1];
            
//            if (i == 0) {
//                [btn setImgviewWithName:[NSString stringWithFormat:@"%@_sel",self.imgs[i]]];
//                btn.userInteractionEnabled = false;
//            }
            
            
            
        }
        

        
        
    }
    return self;
}

-(void)btnclick:(KindButton*)sender
{


    // todo----- 监听点击事件来刷新collectionview的显示内容
    
    
    for (int i = 0 ; i<self.buttons.count; i++) {
        if (i == sender.tag) {
//            NSString* imgsel = [NSString stringWithFormat:@"%@_sel",self.imgs[sender.tag]];
//            [sender setImgviewWithName:imgsel];
            sender.userInteractionEnabled = false;
            [self refresh:i];
        }
        else
        {
            KindButton* btn = self.buttons[i];
            btn.userInteractionEnabled = true;
            [btn setImgviewWithName:self.imgs[i]];
        }
    }
    
    
}

-(void)refresh:(int)i
{
    UIView* view = self;
    
    do {
        view = view.superview;
    } while (![view isKindOfClass:[HallLottery class]]);
    


    HallLottery* lottery = (HallLottery*)view;
    [lottery refreshViewWithIndex:i];

    
}

@end
